-----------------------------------------------------------------------
-- File:        Projdefs.ads
-- Description: Provides type declarations
--
-- Requires:    Unsigned_Types,Raildefs,Swindows,Topolog2
--
--				
-- Author:     Ha Le, Maria Mitrevska
-----------------------------------------------------------------------
with Unsigned_Types;
use Unsigned_Types;
with Raildefs;
use Raildefs;
with Swindows;
with Topolog2;
use Topolog2;

package Projdefs is
   type Widget_Id is range 1..3;
   type Speed_Type is range 0..9;
  --Constant
   SPEED_STEP:  Unsigned_8 := 30;
   SPEED_SLOW: Unsigned_8; -- To be set in Controllers ADB to adapt both Real and Simu
   SPEED_SLOW_T1: Unsigned_8; -- special for train with high load

   --MAX_SPEED: Unsigned_8 := 255;
   --MIN_SPEED: Unsigned_8 := 0;
   type Train_Init_Position is array (Train_Id) of Sensor_Idx;	
   Tram_Id: Train_Id := 3;
   type Debug_Array is array (Train_Id) of Swindows.Window;


   Is_Dangerous_Sensor : constant
   array(Polarity_Type,Sensor_Id) of Boolean :=(
        Fwd =>(21|30|43|62=>True,  -- Boundary
           	   48|63|39 => True, -- Side Swipe
               34|45|35|46|64|38|8|6|4 => True, -- Diverging Turnouts
               33               => True,    -- Dead End
           	  others=>False),
        Rev => (47|58|53=>True,       -- Side Swipe
                26|16|14|12|51|41=> True, -- Diverging Turnouts
                7|5|3 => True,        --Dead End
            others=>False
        ));
    type Chained_Turnout is record
        Block1    : Block_Idx;
        Block2    : Block_Idx;
    end record;

    Chained_Turnout_Record : constant
        array (Polarity_Type,Block_Idx) of Chained_Turnout:=(
        Fwd => ( 13 => Chained_Turnout'(7,14),
                 6 => Chained_Turnout'(7,14),
                 17 => Chained_Turnout'(10,18),
                 9 => Chained_Turnout'(10,18),
                 others => Chained_Turnout'(0,0)),
        Rev => ( 14 => Chained_Turnout'(6,13),
                7 => Chained_Turnout'(6,13),
                10 => Chained_Turnout'(17,9),
                8 => Chained_Turnout'(17,9),
                 others => Chained_Turnout'(0,0))
        );

   Opposite_Bit: array (Sensor_Bit) of Sensor_Bit := (On => Off,Off=>On);
   Max_Feature_Buffer: constant Natural := 2;
   type Feature_Descriptor_Extended(Kind : Feature_Kind := Plain_Track) is
   record
      --Is_An_End : Boolean := False;
      Block_Num    : Block_Idx;
	  Complete		:Boolean;
      Block_Next   :Block_Idx := No_Block;
      case Kind is
         when Sensor =>
            Sid     : Sensor_Id;
            Block2 : Block_Idx := No_Block;     -- /= No_Block if boundary
         when Turnout =>
            Tid    : Turnout_Idx := No_Turnout;
			Tid2 	: Turnout_Idx := No_Turnout;  -- chained
			Setting : Turnout_Pos := Middle; -- 1 Middle if dont need
			Setting2  : Turnout_Pos  := Middle; -- for chained
			Block_Tn2   : Block_Idx := No_Block; -- for chained
            Next_Tu : Feature_Idx;  -- internal use
         when Boundary_Zone =>
            Zid    : Zone_Id := No_Sensor;  -- the id of the boundary sensor (v2.2)
         when Crossing_Track =>
            Kid    : Crossing_Id;
			Kid2	: Crossing_Id; -- for tram
         when others =>
            null;
      end case;
   end record;
   	

   --Turning Decs

    type Blocks_Fwd is array (1 .. 9) of Block_Id;
    type Blocks_Rev is array (1 .. 9) of Block_Id;
    
    Bl_Fwd : Blocks_Fwd := (6, 7, 9, 12, 12, 16, 16, 10,24);
    Bl_Rev : Blocks_Rev := (6, 7, 10, 15, 15, 19, 19, 20,21);
    
    
    type Turnout_Fwd is array (1 .. 9) of Turnout_Idx;
    type Turnout_Rev is array (1 .. 9) of Turnout_Idx;
    
    Tn_Fwd : Turnout_Fwd := (6, 8, 9, 13, 12, 17, 16, 1,1);
    Tn_Rev : Turnout_Rev := (5, 7, 10, 14, 15, 18, 19, 11,11);
    


end Projdefs;
